package com.hsp.Demo_02_array;

public class Demo_11 {
    public static void main(String[] args) {
        /*
        {10, 12, 45, 90}  插入一个23，变成
        {10, 12, 23, 45, 90}
         */

        int[] arr = {10, 12, 45, 90};
        int[] arr2 = new int[arr.length+1];
        boolean flag = true;
        int insertNum = 23;

        for(int i = 0, j = 0; j < arr.length; i++){
            if(arr[j] < insertNum){
                arr2[i] = arr[j];
                j++;
            }else{
                if(flag){
                    arr2[i] = insertNum;
                    flag = false;
                }else{
                    arr2[i] = arr[j];
                    j++;
                }
            }
        }

        if(flag){
            arr2[arr.length] = insertNum;
        }

        for(int i = 0; i < arr2.length; i++){
            System.out.print(arr2[i] + " ");
        }
    }
}
